/*
 * @Author: SamZhang SamZhang@apjcorp.com
 * @Date: 2022-07-13 10:32:27
 * @LastEditors: SamZhang SamZhang@apjcorp.com
 * @LastEditTime: 2022-11-28 17:37:12
 * @FilePath: /circulation-web/webpack.common.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");

module.exports = {
  entry: {
    app: ["./src/stylesheets/app.scss", "./src/index.tsx"],
  },
  output: {
    // path: path.resolve(__dirname, "./dist"),
    // path: path.resolve(__dirname, "/Users/bable/Documents/Develope/Project/MOEEBR/circulation/static/admin-react"), // 开发环境 与后端admin联动
    path: path.resolve(__dirname, "../circulation/static/admin-react"), // 开发环境 与后端admin联动
    filename: "circulation-web.js",
    library: "CirculationWeb",
    libraryTarget: "umd",
  },
  plugins: [
    new CleanWebpackPlugin(),
    // jsdom is needed for server rendering, but causes errors
    // in the browser even if it is never used, so we ignore it:
    new webpack.IgnorePlugin(/jsdom$/),
    // Extract separate css file.
    new MiniCssExtractPlugin({ filename: "circulation-web.css" }),
    // Set a local global variable in the app that will be used only
    // for testing AXE in development mode.
    new webpack.DefinePlugin({
      "process.env.TEST_AXE": JSON.stringify(process.env.TEST_AXE),
    }),
  ],
  optimization: {
    minimizer: [new TerserPlugin({ terserOptions: { compress: false } })],
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
      },
      {
        test: /\.tsx?$/,
        exclude: [/node_modules/],
        loaders: ["ts-loader"],
      },
      {
        test: /\.(ttf|woff|eot|svg|png|woff2|gif|jpg)(\?[\s\S]+)?$/,
        loader: "url-loader?limit=100000",
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js", ".scss"],
    alias: {
      react: path.resolve("./node_modules/react"),
    },
  },
};
